﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Andrewl.XnaHelpers.IO
{
    public static class FileReader
    {
        //StreamReader so we can read files 
        public static StreamReader fileReader;
        //Accessor to our StreamReader
        public static StreamReader Reader
        { get { return fileReader; } }
        //Set the path for our StreamReader
        public static void SetPath(string path)
        {
            fileReader = new StreamReader(path);
        }
        /// <summary>
        /// Will use the storage path set in the XnaHelers class
        /// </summary>
        public static void SetPath()
        {
            fileReader = new StreamReader(XnaHelpers.storage.Path);
        }
        /// <summary>
        /// Reads in the current line of the file and 'consumes' it
        /// </summary>
        /// <returns></returns>
        public static string ReadLine()
        {
            if (!fileReader.EndOfStream)
            {
                return fileReader.ReadLine();
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// Reads in the entire file as a string
        /// </summary>
        /// <returns></returns>
        public static string ReadAll()
        {
            return fileReader.ReadToEnd();
        }
        /// <summary>
        /// Closes the StreamReader so that other programs can access the file
        /// </summary>
        public static void Release()
        {
            fileReader.Dispose();
        }
    }
}